import numpy as np
from pandas import DataFrame

# 抽样
data = np.random.randint(0, 150, size=(4, 4))
index = ['张三', '李四', '王五', '赵六']
columns = ['语文', '数学', '英语', 'python']
df = DataFrame(data, index, columns)
print(df)
print(df.take([3, 2]))  # 使用的是隐式索引
print(df.take([3, 2], axis=1))
## 无放回抽样
## np.random.permutation和take结合可实现无放回抽样
print(df.take(np.random.permutation([0, 1, 2, 3])))
## 有放回抽样
## np.random.randint和take结合可实现无放回抽样
print(df.take(np.random.randint(0, 4, size=4)))
